<?php 
/**
 * ... ...
 * ... ...
 *
 */ 

/**
 * 视图类 JJ_MainWindow 
 *
 * @access public
 */
class JJ_MainWindow 
	//<<[UnmodifiableBlock.Start]::Extends And Implements::>>//
	extends JCAT_ViewGtk
	//<<[UnmodifiableBlock.End]::Extends And Implements::>>// 
{
	
	/**
	 * 构造函数 
	 *
	 * @access	public
	 * @param	$aParent	JCAT_IViewContainer		视图的父对象(父视图 或 控制器)。注意：视图不应单独存在，必须有一个父对象！ 
	 * @return	void
	 */
	public function JJ_MainWindow(JJ_MainController $aParent)
	{
		// 调用父类构造函数 
		//<<[UnmodifiableBlock.Start]::Call Parent Construct::>>//
		$this->JCAT_ViewGtk('JJ_MainWindow','template.JJ_MainWindow.glade','JJ_MainWindow',$aParent) ;
		//<<[UnmodifiableBlock.End]::Call Parent Construct::>>// 

		$this->Initialize() ;
	}
	
	/**
	 * 初始化 视图 
	 *
	 * @access	protected
	 * @return	void
	 */
	protected function Initialize()
	{
		// 子视图
		$aContactListView = new JJ_ContactListView($this) ;
		$this->AddView($aContactListView) ;
		
		// 创建Gtk窗体 
		$aWidget = $this->Create() ;		

		// 窗口标题
		$aSetting = JJ_Setting::GetGlobalInstance() ;
		$aWidget->set_title( $aSetting->GetItem('/JJ','ProductName') ) ;
		
		// 样式菜单
		$this->LoadUIStyleMenu() ;
	}
	
	/**
	 * 加载样式菜单
	 *
	 * @access	protected
	 * @return	void
	 */
	protected function LoadUIStyleMenu()
	{
		$wndMenuUIStyle = $this->GetChildWidget('MenuUIStyle') ;
		
		$aIterator = new JCAT_FSOIterator(ROOT_PATH.'Resource/Style',JCAT_FSOIterator::DIR|JCAT_FSOIterator::RETURN_NAME) ;
		$aIterator->First() ;
		while( !$aIterator->IsDone() )
		{
			$sDirName = $aIterator->Current() ;
			
			if( is_file(ROOT_PATH."Resource/Style/{$sDirName}/gtkrc") )
			{
				$wndMenuItem = new GtkMenuItem($sDirName) ;
				$wndMenuItem->set_visible( true ) ;
				$wndMenuItem->connect_simple('activate',array($this,'OnChangeUIStyle'),$sDirName);
				$wndMenuUIStyle->append($wndMenuItem);
			}
			
			$aIterator->Next() ;
		}
	}
	
	/**
	 * 取得父控制器
	 *
	 * @access	public
	 * @param	$aXMPPConn	Jabber
	 * @return	JJ_MainController
	 */
	public function GetParentController()
	{
		return parent::GetParentController() ;
	}
	
	/**
	 * 取得 联系人清单 视图
	 *
	 * @access	public
	 * @return	JJ_ContactListView
	 */
	public function GetContactListView()
	{
		return $this->GetView('JJ_ContactListView') ;
	}

	/**
	 * 响应关闭事件
	 *
	 * @access	public
	 * @return	bool
	 */
	public function OnClose($bRequestExit=true)
	{
		if( $bRequestExit )
		{
			$aSetting = JJ_Setting::GetGlobalInstance() ;
			$sProductName = $aSetting->GetItem('/JJ','ProductName') ;
			
			if( JCAT_Gtk::ConfirmDialog(
					JCAT_Language::Sentence('是否关闭 %s', $sProductName)
					, JCAT_Language::Sentence('正在关闭 %s', $sProductName)
			))
			{
				$this->GetParent()->Terminate() ;
				return false ;
			}
			
			else 
			{
				return true ;
			}
		}
		
		else
		{
			$this->ShowView(false);
			return true ;
		}
	}

	/**
	 * 响应关闭事件
	 *
	 * @access	public
	 * @return	bool
	 */
	public function OnLogout()
	{		
		if( JCAT_Gtk::ConfirmDialog(
				JCAT_Language::Sentence('是否注销用户')
				, JCAT_Language::Sentence('正在注销')
		))
		{
			// 取消自动登录	
			$aSetting = JJ_Setting::GetGlobalInstance() ;
			$aSetting->SetItem('/JJ/Login','AutoLogin',false) ;
		
			// 销毁窗口
			$this->GetWidget()->destroy() ;
			
			// 退出
			$this->GetParent()->Terminate(false) ;
		}
	}

	/**
	 * Description
	 *
	 * @access	public
	 * @return	void
	 */
	public function OnOpenSessionHistoryDialog()
	{
		$aMainController = $this->GetParentController() ;
		$aSessionHistoryDialog = $aMainController->GetSessionHistoryDialog() ;
		$aSessionHistoryDialog->ShowView(true) ;
	}

	/**
	 * 更换界面外观
	 *
	 * @access	public
	 * @return	void
	 */
	public function OnChangeUIStyle($sStyleName)
	{
		$aSetting = JJ_Setting::GetGlobalInstance() ;
		$aSetting->SetItem('/JJ','Style',$sStyleName) ;
		
		JCAT_Gtk::MessageDialog(JCAT_Language::Sentence('新的界面外将在重启应用程序后生效。')) ;
	}
	
	/**
	 * 下载 样式
	 *
	 * @access	public
	 * @return	void
	 */
	public function OnDownloadUIStyle()
	{
		JJ::OpenWebpage('http://www.gnome-look.org');
	}
	
	/**
	 * 关于
	 *
	 * @access	public
	 * @return	void
	 */
	public function OnAbout()
	{
		JJ::OpenWebpage('http://jj.jecat.cn') ;
	}

	/**
	 * 复制账号地址
	 *
	 * @access	public
	 * @return	void
	 */
	public function OnCopyMyAddress()
	{
		$aMainController = $this->GetParentController() ;
		$aAccount = $aMainController->GetCurrentAccount() ;

		$aClipboard = new GtkClipboard($this->GetWidget()->get_display(),Gdk::atom_intern('CLIPBOARD'));
		$aClipboard->set_text($aAccount->GetJabberAddress());
	}
}

?><?
/**
 * [注意!!]
 *	以下内容由 JCAT PHP Toolbox 自动维护，手动更改的内容会被 JCAT PHP Toolbox 抹除，
 *	同时还可能破坏格式，导致 JCAT PHP Toolbox 无法正常读取。
 */
/*<<[UnmodifiableBlock.Start]::Coder Dialog Data::>>&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&//
<<{{DocumentClass:ViewGtkDoc}}>>
eCVEQSU3RFMlNUQlOEYlREE4JTE0JTdEXyVBOSUzRiVBMiVGOSUwMSUwRCUxRiVBMTMlMERVJTI1JUM4JUM3bCVBQ3UlQTglODMlOUQlOEElQkVUJTI5WCU5MCVDNCUxMCUxNlIlRDEwJUUyJUJGJUVGJUI5ZiU4Nm13JUE3JTdEJTg4bF9fJTlG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